/*
 * Copyright (c) 2011 CCXE(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCXE(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCXE(China) Co.,Ltd.
 *
 * Author: zhaoshujin
 * Date: 2011-10-13 下午05:06:34
 */
package com.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author zhaoshujin
 * 
 */
public class TestJDBC {

	public static void main(String args[]) {

		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		String drv = null;
		Properties p = new Properties();

		long start01 = System.currentTimeMillis();

		try {
			// Begin creating the CONNECTION POOL...
			System.out.println("Begin creating the CONNECTION ...");
			Class.forName("oracle.jdbc.driver.OracleDriver");
		} catch (java.lang.ClassNotFoundException e) {

			System.err.println("mydb(): " + e.getMessage());
		}

		try {
			conn = DriverManager.getConnection("jdbc:oracle:thin:@10.0.1.28:1521:ccx", "ccxetest", "888888");
		} catch (SQLException ex) {
			System.err.println("conn:" + ex.getMessage());
		}

		if (conn != null)
			System.out.println("connection successful");
		else
			System.out.println("connection failure");

		long end01 = System.currentTimeMillis();
		System.out.println("CONNECTION(ms):" + (end01 - start01));

		long start02 = System.currentTimeMillis();

		try {
			// Begin creating the STATEMENT...
			System.out.println("Begin creating the STATEMENT ...");
			stmt = conn.createStatement();

		} catch (SQLException ex) {
			System.err.println("createstatement();" + ex.getMessage());

		}

		long end02 = System.currentTimeMillis();
		System.out.println("STATEMENT(ms):" + (end02 - start02));

		long start03 = System.currentTimeMillis();

		try {
			// Begin Query Table CCXE.VBA_CACHE_VERSION_CONTROLLER...
			System.out.println("Begin Query DB ...");
			rs = stmt.executeQuery("select sysdate from dual");

		} catch (SQLException ex) {
			System.err.println("stmt.excutequery();" + ex.getMessage());

		}

		System.out.println("-----------------------------------");
		try {
			while (rs.next()) {

				System.out.println("SYSDATE: " + rs.getString(1));

			}

		} catch (SQLException ex) {
			System.err.println("a error is failure:" + ex.getMessage());

		}
		System.out.println("-----------------------------------");

		long end03 = System.currentTimeMillis();
		System.out.println("QUERY(ms):" + (end03 - start03));

		p = System.getProperties();

		drv = p.getProperty("java.class.path");
		System.out.println("driver=" + drv);

		long end = System.currentTimeMillis();

		System.out.println("TOTAL(ms):" + (end - start01));

	}

}
